﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ArticlePublish.aspx.cs" Inherits="admin_ArticlePublish" MasterPageFile="~/admin/AdminMasterPage.master" %>

<asp:Content ID="header" ContentPlaceHolderID="head" runat="server">
    <link href="../editor/themes/default/default.css" rel="stylesheet" />
    <link href="../editor/plugins/code/prettify.css" rel="stylesheet" />
    <link href="http://cdn.bootcss.com/sco.js/1.1.0/css/sco.message.css" rel="stylesheet" />
    <style type="text/css">
        #textMessage {
            margin-bottom: 5px;
        }

        #textfinlly {
            display: none;
        }
    </style>
</asp:Content>

<asp:Content ID="main" ContentPlaceHolderID="main" runat="server">
    <div class="panel panel-default">
        <div class="panel-body">
            <blockquote>
                <p style="font-family: 'Microsoft YaHei'">文章发布</p>
            </blockquote>
            <div class="input-group">
                <span class="input-group-addon">标题</span>
                <input type="text" id="Title_text" class="form-control" placeholder="请输入标题" />
            </div>
            <div style="border-left: 5px solid #00ff21; padding: 10px;">
                <label class="radio-inline">
                    <input type="radio" name="inlineRadioOptions" id="Radio1" value="1" />
                    律师文集
                </label>
                <label class="radio-inline">
                    <input type="radio" name="inlineRadioOptions" id="Radio2" value="2" />
                    案例分析
                </label>
                <label class="radio-inline">
                    <input type="radio" name="inlineRadioOptions" id="Radio3" value="3" />
                    法律解答
                </label>
                <label class="radio-inline">
                    <input type="radio" name="inlineRadioOptions" id="Radio4" value="4" />
                    律师实务
                </label>
            </div>
            <div id="textMessage">
                <asp:TextBox ID="KEContent" runat="server" Style="width: 100%; height: 300px" TextMode="MultiLine" />
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div id="textfinlly" class="alert alert-success text-left" role="alert"></div>
                </div>
                <div class="col-md-4">
                </div>
                <div class="col-md-4">
                    <div class="text-right">
                        <button type="button" id="Publish" class="btn btn-primary btn-lg btn-block">发布</button>
                    </div>
                </div>
            </div>

        </div>
    </div>
</asp:Content>
<asp:Content ID="js" ContentPlaceHolderID="footJS" runat="server">
    <script charset="utf-8" src="../editor/kindeditor.js"></script>
    <script charset="utf-8" src="../editor/lang/zh_CN.js"></script>
    <script charset="utf-8" src="../editor/plugins/code/prettify.js"></script>
    <script type="text/javascript" src="http://cdn.bootcss.com/sco.js/1.1.0/js/sco.message.js"></script>
    <script type="text/javascript">
        var editorhtml;
        var endb = false;
        var Btext = false;
        var classNum;
        var textcount;
        KindEditor.ready(function (K) {
            var editor1 = K.create('#<%=KEContent.ClientID%>', {
                cssPath: '../editor/plugins/code/prettify.css',
                uploadJson: '../editor/asp.net/upload_json.ashx',
                fileManagerJson: '../editor/asp.net/file_manager_json.ashx',
                allowFileManager: true,
                items: [
            'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
            'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
            'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
                afterChange: function () {
                    textcount = this.count('text');
                    if (textcount) {
                        editorhtml = editor1.html();
                        if (textcount <= 5000) {
                            $("#textfinlly").show('fast').text("您还可以输入" + (5000 - textcount) + "个文字");
                            endb = false;
                        }
                        else {
                            $("#textfinlly").show('fast').text("您不能再输入信息了！");
                            endb = true;
                        }
                        Btext = true;
                    }
                },
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                }
            });
            prettyPrint();
        });
        $(document).ready(function () {
            $(".navbar-collapse").find("li").eq(1).addClass("active").siblings().removeClass("active");
            $("#Publish").click(function () {
                classNum = $('input:radio:checked').val();
                if (Btext == true && endb == false && $('#Title_text').val() != "" && textcount > 0 && classNum != null) {
                    Publish();
                }
                else {
                    $('#textfinlly').show().text('信息有误！请重新填写');
                    $.scojs_message('请填写完整的资料信息！', $.scojs_message.TYPE_ERROR);
                }

            });

        });
        function Publish() {
            $.ajax({
                type: "POST",
                url: "ajax/ArticlePublish.ashx",
                data: { 'Title': $("#Title_text").val(), 'textContent': editorhtml, 'class': classNum },
                datatype: "text/json",
                beforeSend: function () {
                    $('#textfinlly').text('发布中...');
                    $.scojs_message('发布中...', $.scojs_message.TYPE_OK);
                },
                success: function (msg) {
                    if (msg == "1") {
                        $('#textfinlly').show().text('发布成功！');
                        $.scojs_message('发布成功！', $.scojs_message.TYPE_OK);
                    }
                    else {
                        $('#textfinlly').show().text('发布失败！');
                        $.scojs_message('发布失败！', $.scojs_message.TYPE_ERROR);

                    }
                },
                complete: function (data) {

                }
            });
        }
    </script>
</asp:Content>
